home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 32-bit_x86 / Italiano / cpsimage.cab / data / pdf / ims2pdf.elf < prev   
Text File  |  2009-03-16  |  2KB  |  70 lines

  1.  
  2. // The TimeCheck() function reports the time to this point in the execution
  3. print "time to start interpreter = " + TimeCheck() + "secs";
  4.  
  5. // Load declarations and support procedures
  6. #import "documentio.ucm";
  7. #import "fiji2xip.ucm";
  8. #import "fwx2xip.ucm";
  9. #load   "xipProcs/printLayer.proc";
  10. #load   "xipProcs/getOcrPage.proc";
  11. #load   "sys/stdlib.elf";
  12.  
  13. // Load image functions and methods
  14. LoadClasses ( filename: "xeng" );
  15.  
  16.  
  17. IMPORT STRING dir;
  18. IMPORT STRING language = "English";
  19. IMPORT INTEGER ocr = 1;     // Default is on
  20. STRING ocrformat = "XDOC";
  21. STRING ocrxdoc, ocrxml;
  22. FILE   file = new (FILE, path:dir);
  23.  
  24. // Test for proper parameters
  25. if ( !dir || !file.isDirectory() )
  26.   { print "Usage: \"xipe ims2pdf.elf -im dir:s language:s ocr:i 0|1\" " +
  27.             "\n\twhere dir is a directory with images to be packaged"; end; }
  28.  
  29. LIST filelist = file.list ();
  30. STRING outpdf = dir.name() + ".pdf";
  31.  
  32. // Make a DOCUMENTWRITER
  33. print "creating PDF writer";
  34. DOCUMENTWRITER docwrite = CreateDocumentWriter (filename:outpdf);
  35.  
  36.  
  37. // Read and segment image
  38. XIPIMAGE ims, thumb, ocrimg;
  39. INTEGER i;
  40. for (i=0; filelist[i]; i++) {
  41.    ims = ReadIMS (filename: dir + "/" + filelist[i]);
  42.  
  43.    // Add thumbnail to segmented image
  44.    if (ims.getMember (member: "layerType") == XIP_Binary)
  45.      ims.addLayer(image:ims.unCompress().invert().thumbnail( size: (150,150)),
  46.                 ltype: XIP_Thumbnail);
  47.    else
  48.      ims.addLayer(image:ims.unCompress().thumbnail( size: (150,150)),
  49.                 ltype: XIP_Thumbnail);
  50.  
  51.    if (ocr) {
  52.       print "OCR " + file  + "...";
  53.       ocrimg = getOcrPage (input: ims);
  54.       ocrxdoc = ocrimg.fwxOCR (texttype: ocrformat, language: language);
  55.       XIPIMAGE ocrxip = XDOCtoXIPXML(xdoc: ocrxdoc);
  56.          ocrxip.setMember(num:0, member:"visibility", value: FALSE);
  57.       ims.addLayer(image:ocrxip, ltype: XIP_Text);
  58.     }
  59.  
  60.    // Add page to the DOCUMENT
  61.    docwrite.appendPage (pgImg: ims);
  62. }
  63.  
  64.  
  65. docwrite.release();
  66.  
  67. // How long has this taken
  68. print TimeCheck();
  69. print "output pdf file = " + outpdf;
  70.